﻿#region Copyright Notice
// This file is part of GestionPedago.
// <description>
// Copyright (C) 2012 ENI Ecole Informatique
// 
// GestionPedago is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
// 
// <program> is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.
// 
// You should have received a copy of the GNU General Public License
// along with this program.  If not, see <http://www.gnu.org/licenses/>.
#endregion

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using GestionPedago.Services.Framework;
using GestionPedago.Services.ES;
using GestionPedago.Services.ES.Modele;
using GestionPedago.EntityContext;
using Persistence.OPManager;
using GestionPedago.Services.Mapping;

namespace GestionPedago.Services.Traitement
{
    /// <summary>
    /// Classe de traitement du service AfficherResultats
    /// </summary>
    public class AfficherResultatsTraitement : ITraitement<AfficherResultatsIn,AfficherResultatsOut>
    {
        private static AfficherResultatsTraitement instance;

        public static AfficherResultatsTraitement GetInstance() {
            if (instance == null)
            {
                instance = new AfficherResultatsTraitement();
            }
            return instance;
        }

        private AfficherResultatsTraitement() { }

        /// <summary>
        /// Méthode de traitement
        /// </summary>
        /// <param name="paramEntree">Le paramètre d'entrée du service AfficherResultats</param>
        /// <returns>Le paramètre de sortie du service AfficherResultats</returns>
        public AfficherResultatsOut Traitement(AfficherResultatsIn paramEntree)
        {
         
            PlanningIndividuelFormation pif = new PlanningIndividuelFormationMappeur().ES2Entity(paramEntree.PlanningIndividuelFormation);
            List<ResultatES> listeResultats = new List<ResultatES>();
            
            foreach(ActiviteParTitre apt in FormationOPManager.GetFormationByCode(paramEntree.PlanningIndividuelFormation.CodeFormation).Titre.ActiviteParTitre){
                foreach (CompetenceParActivite cpa in apt.Activite.CompetenceParActivite)
                {

                    ResultatES res = new ResultatES();

                    res.Libelle =  apt.Activite.Libelle + ": ";
                    res.Libelle += cpa.Competence.Libelle + ":";
                    int i = 0;
                    foreach (ValidationCompetence vc in pif.GetListeValidationCompetence(cpa.Competence))
                    {
                        if(i == 0) {
                            res.Libelle += " " + vc.PlanningECFDetail.PlanningECF.ECF.Libelle + ": ";
                        } else {
                            res.Libelle += ", " + vc.PlanningECFDetail.PlanningECF.ECF.Libelle + ": ";
                        }
                        if(vc.Statut == null) {
                            res.Libelle += "Non corrigé";
                        } else {
                            res.Libelle += vc.Statut;
                        }
                        i++;
                    }
                    listeResultats.Add(res);
                }
            }
          
            AfficherResultatsOut paramSortie = new AfficherResultatsOut();

            paramSortie.ListeResultats = listeResultats;

            return paramSortie;
        }
    }
}
